<template>
  <div class="side">
    <!-- 提交 -->
    <div class="regiter">
      <el-row>
        <el-button @click="createData()" class="dakai" type="primary">提交</el-button>
      </el-row>
    </div>
    <div style="width:100%;">
      <el-form :model="PaymentSet" label-position="right" label-width="181px" ref="dataForm">
        <el-form-item label="支付功能">
          <el-radio-group v-model="PaymentSet.payStatus">
            <el-radio label="1">开启</el-radio>
            <el-radio label="0">关闭</el-radio>
          </el-radio-group>
          <p style="margin:0;color:#606266">提示：关闭支付功能将导致网校用户无法购买商品。</p>
        </el-form-item>
        <!-- 关闭支付时显示 -->
        <el-form-item label="支付关闭时的提示信息" v-show="!PaymentSet.payStatus">
          <el-input :rows="4" style="width:330px" type="textarea" v-model="PaymentSet.message"/>
        </el-form-item>


        <!-- 开启支付时展示 -->
        <div v-show="PaymentSet.payStatus === '1'">
          <div class="zhifubao">支付宝</div>
          <el-form-item label="接口状态">
            <el-radio-group v-model="PaymentSet.aliStatus">
              <el-radio label="1">开启</el-radio>
              <el-radio label="0">关闭</el-radio>
            </el-radio-group>
          </el-form-item>

          <div v-show="PaymentSet.aliStatus ==='1'">

            <el-form-item label="应用ID">
              <el-input style="width:600px;" v-model="PaymentSet.aliAppId"></el-input>
            </el-form-item>

            <el-form-item label="商户私钥">
              <el-input :rows="10" type="textarea" style="width:600px;" v-model="PaymentSet.aliMerchantPrivateKey"></el-input>
            </el-form-item>

            <el-form-item label="支付宝公钥">
              <el-input :rows="10" type="textarea" style="width:600px;" v-model="PaymentSet.aliPayPublicKey"></el-input>
            </el-form-item>

            <!--<el-form-item label="服务器异步通知页面路径">-->
              <!--<el-input style="width:600px;" v-model="PaymentSet.aliNotifyUrl"></el-input>-->
            <!--</el-form-item>-->

            <!--<el-form-item label="页面跳转同步通知页面路径">-->
              <!--<el-input style="width:600px;" v-model="PaymentSet.aliReturnUrl"></el-input>-->
            <!--</el-form-item>-->

            <!--<el-form-item label="签名方式">-->
              <!--<el-input style="width:600px;" v-model="PaymentSet.aliSignType" readonly="readonly"></el-input>-->
            <!--</el-form-item>-->

            <!--<el-form-item label="字符编码格式">-->
              <!--<el-input style="width:600px;" v-model="PaymentSet.charset" readonly="readonly"></el-input>-->
            <!--</el-form-item>-->

            <!--<el-form-item label="支付宝网关">-->
              <!--<el-input style="width:600px;" v-model="PaymentSet.aliGateWayUrl" readonly="readonly"></el-input>-->
            <!--</el-form-item>-->
          </div>
        </div>

        <!-- 微信支付 -->
        <div v-show="PaymentSet.payStatus==='1'">
          <div class="xiaowei">微信支付</div>
          <el-form-item label="接口状态">
            <el-radio-group v-model="PaymentSet.wechatStatus">
              <el-radio label="1">开启</el-radio>
              <el-radio label="0">关闭</el-radio>
            </el-radio-group>
          </el-form-item>
          <div v-show="PaymentSet.wechatStatus==='1'">
            <el-form-item label="AppID">
              <el-input style="width:600px;" v-model="PaymentSet.appId"></el-input>
            </el-form-item>
            <el-form-item label="AppSecret">
              <el-input style="width:600px;" v-model="PaymentSet.appSecret"></el-input>
            </el-form-item>
            <el-form-item label="MP文件验证码">
              <el-input :rows="4" type="textarea" style="width:600px;" v-model="PaymentSet.mp"></el-input>
            </el-form-item>
            <el-form-item label="商户号">
              <el-input style="width:600px;" v-model="PaymentSet.mchId"></el-input>
            </el-form-item>
            <el-form-item label="ip">
              <el-input style="width:600px;" v-model="PaymentSet.spBillCreateIp"></el-input>
            </el-form-item>
            <el-form-item label="域名">
              <el-input style="width:600px;" v-model="PaymentSet.domain"></el-input>
            </el-form-item>
            <el-form-item label="支付说明">
              <el-input :rows="4" type="textarea" style="width:600px;" v-model="PaymentSet.payBody"></el-input>
            </el-form-item>
            <el-form-item label="微信商户平台API密钥">
              <el-input :rows="4" type="textarea" style="width:600px;" v-model="PaymentSet.token"></el-input>
            </el-form-item>
            <el-form-item label="安全证书">
              <el-input :rows="4" type="textarea" style="width:600px;" v-model="PaymentSet.securityCertificate"></el-input>
            </el-form-item>
            <el-form-item label="支付密钥">
              <el-input style="width:600px;" v-model="PaymentSet.privateKey"></el-input>
            </el-form-item>
          </div>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
  import {addPaymentSet, getPaymentSet} from '@/api/system/payment_set';
  import {getTenantId} from '@/utils/auth';

  export default {
    data() {
      return {
        PaymentSet: {
          payStatus: '1',
          aliStatus: '1',
          aliNotifyUrl: '',
          aliReturnUrl: '',
          aliAppId: '',
          aliMerchantPrivateKey: '',
          aliPayPublicKey: '',
          aliSignType: '',
          charset: '',
          aliGateWayUrl: '',
          wechatStatus: '1',
          appId: '',
          appSecret: '',
          mp: '',
          merchantNumber: '',
          spBillCreateIp: '',
          payBody: '',
          domain: '',
          mchId: '',
          securityCertificate: '',
          privateKey: '',
          token: ''
        }
      };
    },
    created() {
      this.fetchData()
    },
    methods: {
      fetchData() {
        getPaymentSet(getTenantId()).then(response => {
          if (response.data) {
            this.PaymentSet = response.data
          }
        }).catch(err => {
          console.log(err)
        })
      },
      createData() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.PaymentSet.tenantId = getTenantId();
            addPaymentSet(this.PaymentSet).then(() => {
              this.$notify({
                title: '成功',
                message: '操作成功',
                type: 'success',
                duration: 2000
              });
              this.fetchData();
            })
          }
        })
      }
    }
  };
</script>

<style lang="scss" scoped>
  .regiter {
    width: 100%;
    height: 44px;
    line-height: 44px;
    padding-left: 10px;
    background-color: #e7e9ed;
    padding-top: 15px;
    padding-right: 34px;
  }

  .zhifubao {
    width: 100%;
    height: 44px;
    line-height: 44px;
    padding-left: 10px;
    background-color: #f0f3ff;
    padding-right: 34px;
  }

  .xiaowei {
    width: 100%;
    height: 44px;
    line-height: 44px;
    padding-left: 10px;
    background-color: #ebf4ff;
    padding-right: 34px;
  }

  .lianjie {
    width: 100%;
    height: 44px;
    line-height: 44px;
    padding-left: 10px;
    background-color: #e4fafd;
    padding-right: 34px;
  }

  .dakai {
    float: right;
    position: absolute;
    right: 10px;
    bottom: -25px;
  }
</style>
